package com.smartstate.dataManagement.controller;

import com.smartstate.dataManagement.entity.CarbonConfig;
import com.smartstate.dataManagement.service.CarbonConfigService;
import com.smartstate.dataManagement.vo.ResultVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;

@RestController
@RequestMapping("/CarbonConfig")
@ApiOperation("ioc配置参数")
public class CarbonConfigController implements Serializable {


    @Resource
    private CarbonConfigService carbonConfigService;

    @PostMapping("/save")
    @ApiOperation(value = "添加编辑")
    public ResultVO<CarbonConfig> save(@RequestBody CarbonConfig carbonConfig ) {
        //先查询综合态势这个信息是否存在了
        Boolean idByOne = carbonConfigService.getIdByOne(carbonConfig.getConfigItem());
        if (idByOne.equals(true)){
            //没有存在就保存到数据库
            boolean save = carbonConfigService.save(carbonConfig);
            return  ResultVO.ok();
        }
        carbonConfigService.updateByItem(carbonConfig.getConfigItem(),carbonConfig.getConfigDevice());
        return ResultVO.ok(carbonConfigService.getByOne(carbonConfig.getConfigItem()));
    }

}
